open(BUFF,"file1") or die "no file found\n";
while($tfam=<BUFF>)
{
	chomp($tfam);
	$tped=$tfam;
	$tped=~s/tfam/tped/g;
	@dir=split(/\//,$tped);
	pop(@dir);
	$dir=join('/',@dir);
	$plink=$tfam;
	$plink =~ s/\.tfam//g;
	system("cut -c1-12 $tfam|sort|uniq -d > $dir/file");
	#system("grep -f $dir/file $tfam |awk -F '-' '{if($4 ~ /^11/)print $1"-"$2"-"$3" "$1"-"$2"-"$3" "0" "0" ""-"9" ""-"9}'> $dir");
	system("grep -f $dir/file $tfam |awk -F '-' '{if(\$4 ~ /^10/)print \$0}'> $dir/blood");
	system("grep -f $dir/file $tfam |awk -F '-' '{if(\$4 ~ /^11/)print \$0}'> $dir/tissue");
	if(-e "$tped.gz")
	{
		system("gunzip $tped.gz");
	}
	system("plink --tfile $plink --keep $dir/blood --make-bed --out $dir/blood");
	system("plink --tfile $plink --keep $dir/tissue --make-bed --out $dir/tissue");
	system("mv $dir/blood.fam $dir/blood1.fam");
	system("mv $dir/tissue.fam $dir/tissue1.fam");
	system("awk -F '-' '{print \$1\"-\"\$2\"-\"\$3\" \"\$1\"-\"\$2\"-\"\$3\" \"0\" \"0\" \"\"-\"\"9\"\" \"\"-\"\"9\"}' $dir/blood1.fam >$dir/blood.fam");
	system("awk -F '-' '{print \$1\"-\"\$2\"-\"\$3\" \"\$1\"-\"\$2\"-\"\$3\" \"0\" \"0\" \"\"-\"\"9\"\" \"\"-\"\"9\"}' $dir/tissue1.fam >$dir/tissue.fam");
	system("plink --bfile $dir/blood  --merge-mode 7 --bmerge $dir/tissue.bed $dir/tissue.bim $dir/tissue.fam --out $dir/merge");
	system("rm $dir/tissue*");
	system("rm $dir/blood*");
	#die "awesome $dir\n";
}
